package com.hengfoxwolf.ffmpegdemo
import android.os.Bundle
import android.os.Environment
import android.view.View
import com.hengfoxwolf.ffmpegdemo.base.BaseActivity
import com.hengfoxwolf.ffmpegdemo.databinding.ActivityVideoPlayBinding

class VideoPlayActivity :
    BaseActivity<ActivityVideoPlayBinding>(ActivityVideoPlayBinding::inflate), View.OnClickListener {

    private lateinit var mediaPath: String

    private var firstPlay = true
    private var playPause = false

    override fun init(savedInstanceState: Bundle?) {

        mediaPath = Environment.getExternalStorageDirectory().path + "/define/vi01.mp4"
        mBinding.videoPlayPause.setOnClickListener(this)
    }

    override fun onPause() {
        super.onPause()
    }

    override fun onDestroy() {
        super.onDestroy()
        mBinding.videoView.destroy()
    }

    override fun onClick(view: View?) {
        when (view?.id) {
            R.id.video_play_pause -> {
                if (firstPlay) {
                    mBinding.videoView.playVideo(mediaPath)
                    firstPlay = false
                    mBinding.videoPlayPause.text = resources.getString(R.string.txt_pause)
                } else {
                    mBinding.videoPlayPause.text = resources.getString(if (playPause) R.string.txt_pause else R.string.txt_play)
                    mBinding.videoView.playPause(playPause)
                    playPause = !playPause
                }
            }
        }
    }

}